Delbin and msvc improvements. Warning fixes.
authorrobertl <robertl>
Sat, 27 Jun 2009 04:52:07 +0000 (04:52 +0000)
committerrobertl <robertl>
Sat, 27 Jun 2009 04:52:07 +0000 (04:52 +0000)
delbin.c
jeeps/gpsapp.c
kml.c
msvc/GPSBabel-msvc7.vcproj
msvc/GPSBabel.vcproj
naviguide.c
v900.c

index 1ce239a7a8b2ef32c0b419128037e13a01a401ae..cf60ff9c64f97e7255e9913f46202a020fbc528b 100644 (file)
--- a/delbin.c
+++ b/delbin.c
@@ -522,56 +522,67 @@ message_write(unsigned msg_id, message_t* m)
                warning(MYNAME ": sent %x\n", msg_id);
 }
 
+// read from the payload of a single packet
+static unsigned
+read_depacketize_1(gbuint8** p, unsigned n, int new_packet)
+{
+       static gbuint8 buf[256];
+       static unsigned buf_i, buf_n;
+       while (buf_n == 0 || new_packet) {
+               packet_read(buf);
+               if (buf[1] <= delbin_os_packet_size - 2) {
+                       buf_n = buf[1];
+                       buf_i = 2;
+               }
+       }
+       *p = buf + buf_i;
+       if (n > buf_n) {
+               n = buf_n;
+       }
+       buf_n -= n;
+       buf_i += n;
+       return n;
+}
+
+// read from packet payloads until request is fulfilled
+static void
+read_depacketize(gbuint8* buf, unsigned n)
+{
+       while (n) {
+               gbuint8* p;
+               unsigned nn = read_depacketize_1(&p, n, FALSE);
+               memcpy(buf, p, nn);
+               n -= nn;
+               buf += nn;
+       }
+}
+
 // Get one valid message.
 // If a corrupted message with the right id is seen, return failure (0).
 static unsigned
 message_read_1(unsigned msg_id, message_t* m)
 {
-       gbuint8 buf[256];
-       static gbuint8 buf_prev[256];
-       gbuint8* p;
-       unsigned total = 0;
-       unsigned count = 0;
-       unsigned id = 0;
-
+       unsigned id;
        for (;;) {
-               for (;;) {
-                       unsigned n;
-                       // if last packet had extra data
-                       if (buf_prev[1]) {
-                               // try that first
-                               n = buf_prev[1] + 2;
-                               memcpy(buf, buf_prev, n);
-                               buf_prev[1] = 0;
-                       } else {
-                               n = packet_read(buf);
-                       }
-                       if (n >= 10 && buf[2] == 0xdb && buf[3] == 0xfe &&
-                           checksum(buf + 2, 6) == le_readu16(buf + 8))
-                       {
-                               break;
-                       }
+               unsigned total;
+               gbuint8 buf[8];
+               gbuint8* p;
+
+               read_depacketize(buf, 8);
+               while (buf[0] != 0xdb || buf[1] != 0xfe || checksum(buf, 6) != le_readu16(buf + 6)) {
+                       gbuint8* pp;
+                       // try for a message start at the beginning of next packet
+                       read_depacketize_1(&pp, 8, TRUE);
+                       memcpy(buf, pp, 8);
                }
-               count = buf[1] - 8;
-               total = le_readu16(buf + 6);
-               id = le_readu16(buf + 4);
+               id = le_readu16(buf + 2);
+               total = le_readu16(buf + 4);
                message_ensure_size(m, total - 4);
-               memcpy(m->buf, buf, 2 + buf[1]);
-               while (count < total) {
-                       unsigned n;
-                       packet_read(buf);
-                       n = buf[1];
-                       // if packet has more than needed to complete message
-                       if (n > total - count) {
-                               const unsigned n_next = n - (total - count);
-                               n -= n_next;
-                               // save the rest for next time
-                               memcpy(buf_prev + 2, buf + 2 + n, n_next);
-                               buf_prev[1] = n_next;
-                       }
-                       memcpy((char*)m->data + count, buf + 2, n);
-                       count += n;
-               }
+               // copy in message head, really only need id field, do the rest for debugging
+               m->buf[0] = m->buf[1] = 0;
+               memcpy(m->buf + 2, buf, 8);
+               // read message body and trailer
+               read_depacketize(m->data, total);
                p = (gbuint8*)m->data + m->size;
                if (checksum(m->data, m->size) == le_readu16(p) &&
                        p[2] == 0xad && p[3] == 0xbc)
index d87520e50a12aa583e39c645cef7fb33d1fb1484..93f7d8caaa4a9eb1c276ad5ff85fb14b91184daa 100644 (file)
@@ -4301,7 +4301,7 @@ void GPS_D301_Send(UC *data, GPS_PTrack trk, int type)
     p+=sizeof(float);
 
     if (type == 302) {
-      GPS_Util_Put_Float(p,1.0e25);
+      GPS_Util_Put_Float(p, 1.0e25f);
       p+=sizeof(float);
     }
 
@@ -4321,7 +4321,7 @@ void GPS_D304_Send(UC *data, GPS_PTrack trk)
     GPS_Util_Put_Float(p,trk->alt);
     p+=sizeof(float);
 
-    GPS_Util_Put_Float(p, (const float) 1.0e25);
+    GPS_Util_Put_Float(p, 1.0e25f);
     p+=sizeof(float);
 
     /* Not really clear if the members below makes sense to write or not */
diff --git a/kml.c b/kml.c
index b3847c2637302c2b45468de455e1f94043c2d895..66c7cf19277e41379adf196b67608a141fcd67cf 100644 (file)
--- a/kml.c
+++ b/kml.c
@@ -1080,6 +1080,8 @@ static void kml_route_tlr(const route_head *header)
 // the bounding box of our entire data set and set the event times
 // to include all our data.
 void kml_write_AbstractView(void) {
+  double bb_size;
+
   kml_write_xml(1, "<LookAt>\n");
 
   if (kml_time_min || kml_time_max) {
@@ -1115,7 +1117,7 @@ void kml_write_AbstractView(void) {
 
   // It turns out the length of the diagonal of the bounding box gives us a
   // reasonable guess for setting the camera altitude.
-  double bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon,
+  bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon,
                              kml_bounds.max_lat, kml_bounds.max_lon);
   // Clamp bottom zoom level.  Otherwise, a single point zooms to grass.
   if (bb_size < 1000) {
index afe9eba6c72be4159469d1fdf0180345aabea372..1c233077cd8851805acb48fca76fbd5669a8f6b5 100644 (file)
@@ -39,7 +39,7 @@
                                Name="VCCustomBuildTool"/>
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="odbc32.lib odbccp32.lib setupapi.lib"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib setupapi.lib hid.lib"
                                OutputFile=".\Release/GPSBabel.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="TRUE"
                                Name="VCCustomBuildTool"/>
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="odbc32.lib odbccp32.lib setupapi.lib"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib setupapi.lib hid.lib"
                                OutputFile=".\Debug/GPSBabel.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="TRUE"
                                                BrowseInformation="1"/>
                                </FileConfiguration>
                        </File>
+                       <File
+                               RelativePath="..\delbin.c">
+                       </File>
                        <File
                                RelativePath="..\delgpl.c">
                                <FileConfiguration
                                RelativePath="..\pocketfms_fp.c">
                        </File>
                        <File
-                               RelativePath="..\pocketfmt_bc.c">
+                               RelativePath="..\pocketfms_bc.c">
                        </File>
                        <File
                                RelativePath="..\naviguide.c">
index 2f55618410b4a99b496f92257262e82044bea27e..1e57a4b53caabadf7966f17da3722629e8683066 100644 (file)
@@ -78,7 +78,7 @@
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="setupapi.lib"
+                               AdditionalDependencies="setupapi.lib hid.lib"
                                OutputFile=".\Release/GPSBabel.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="setupapi.lib"
+                               AdditionalDependencies="setupapi.lib hid.lib"
                                OutputFile=".\Debug/GPSBabel.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="setupapi.lib expatw\libexpatw.lib"
+                               AdditionalDependencies="setupapi.lib hid.lib expatw\libexpatw.lib"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                                GenerateDebugInformation="false"
                                        />
                                </FileConfiguration>
                        </File>
+                       <File
+                               RelativePath="..\delbin.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\delgpl.c"
                                >
                                RelativePath="..\pocketfms_fp.c">
                        </File>
                        <File
-                               RelativePath="..\pocketfmt_bc.c">
+                               RelativePath="..\pocketfms_bc.c">
                        </File>
                        <File
                                RelativePath="..\naviguide.c">
index bf529874f18bc5baba6cad739b115ae8118b5b50..82c530a98a2c9252e9b03036b186afe443a549ba 100755 (executable)
@@ -302,10 +302,9 @@ wr_init(const char *fname) {
 }
 
 static void
-wr_deinit () {
+wr_deinit(void)
+{
        gbfclose(file_out);     
-       
-       
 }
 
 /*=========================== Read data functions ==================================*/
@@ -354,7 +353,8 @@ ng_read_file_header(void)
 static void
 data_read(void)
 {
-       int n, i;
+       int n;
+       unsigned i;
        waypoint *wpt_tmp;
        
        if (process_rte) {
diff --git a/v900.c b/v900.c
index d6887ef929be05f36f2f91915a88d08cad1306dc..083b73bc02aa531a60ff9998ea046d54bb34fd41 100644 (file)
--- a/v900.c
+++ b/v900.c
@@ -74,6 +74,9 @@ for a little more info, see structures:
 #include <stdio.h>
 #include <assert.h>
 
+#if _MSC_VER
+    #define __func__ __FUNCTION__
+#endif
 
 /* the start of each record (line) is common to both advanced and basic mode.
    it will be parsed by a single common code. hence, it will be easier and clearer